package com.eryos.test.springsecurity.shared;

/**
 * Project :  SpringSecuritySimple
 * Author :   Olivier Combe
 * URL :      http://eryos-tech.blogspot.com/
 *
 * Copyright (C) 2011 - Olivier Combe 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */

import java.io.Serializable;
import java.util.ArrayList;

@SuppressWarnings("serial")
public class SimpleUser implements Serializable {
	
	/* Static attribute used for Datastoring */
	public static final String USER_TYPE 			= "SimpleUser";
	public static final String USER_USERNAME  		= "username"; 
	public static final String USER_ENABLED  		= "enabled";
	public static final String USER_AUTHORITIES 	= "roles";
	public static final String USER_ENCODED_PASS  	= "sha_password";

	private  String username;
	private  String email;
	private  String password;
	private  ArrayList<String> authorities;
	private  boolean enabled;

	public SimpleUser(){
		/* User is disabled by default ( need a mail confirmation to enable ? ) */
		enabled = false;
		
		// TODO use Set instead of ArrayList to avoid duplicate roles
		authorities = new ArrayList<String>();  
		
		/* Default role defined for all users */
		authorities.add("ROLE_USER");
	}
	
	/* ************** Getters & Setters ************** */

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public ArrayList<String> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(ArrayList<String> authorities) {
		this.authorities = authorities;
	}

	public void addAuthority(String authority){
		this.authorities.add(authority);
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
}
